package com.qyhl.module_practice.order.mine;

import com.qyhl.module_practice.common.PracticeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeOrderBean;

import java.util.List;

public class PracticeOrderMineModel implements PracticeOrderMineContract.PracticeOrderMineModel {
    private PracticeOrderMinePresenter mPresenter;

    PracticeOrderMineModel(PracticeOrderMinePresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getList(String volId, String page) {

        EasyHttp.get(PracticeUrl.GET_PRACTICE_MY_VOLUNTEER_ORDER)
                .params("volId", volId)
                .params("page", page)
                .execute(new SimpleCallBack<List<PracticeOrderBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何点单内容！", !page.equals("1"));
                        } else {
                            mPresenter.setError("获取出错，请稍后再试！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<PracticeOrderBean> practiceOrderBeans) {
                        if (practiceOrderBeans != null && practiceOrderBeans.size() > 0) {
                            mPresenter.setList(practiceOrderBeans, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何点单内容！", !page.equals("1"));
                        }
                    }
                });
    }

    @Override
    public void getPublic(String phone, String page) {
        EasyHttp.get(PracticeUrl.GET_PRACTICE_MY_PUBLIC_ORDER)
                .params("phone", phone)
                .params("page", page)
                .execute(new SimpleCallBack<List<PracticeOrderBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何点单内容！", !page.equals("1"));
                        } else {
                            mPresenter.setError("获取出错，请稍后再试！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<PracticeOrderBean> practiceOrderBeans) {
                        if (practiceOrderBeans != null && practiceOrderBeans.size() > 0) {
                            mPresenter.setList(practiceOrderBeans, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何点单内容！", !page.equals("1"));
                        }
                    }
                });
    }
}
